using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;

using phorm.config;
using phorm.database.core;

namespace phorm.database.oracle
{
    static class OracleDatabase
    {
        private static OleDbConnection _connection;
        private static bool _isTransaction;
        public static int counter = 0;

        public static OleDbConnection connection()
        {
            string connectionString = string.Format("provider=MSDAORA;server={0};data source={1};uid={2};password={3};", PhormConfig.phormParams.dbHost, PhormConfig.phormParams.dbName, PhormConfig.phormParams.dbUsername, PhormConfig.phormParams.dbPassword);
            _connection = new OleDbConnection(connectionString);
            return _connection;
        }

        public static OleDbConnection transactionConnection()
        {
            return OracleDatabase.connection();
        }

        public static object query(String query)
        {
            object retVal = null;
            if (query != null)
            {
                try
                {
                }
                catch
                {
                    Console.WriteLine(query);
                }
            }
            return retVal;
        }

        public static object idQuery(String query)
        {
            object retVal = null;
            if (query != null)
            {
                try
                {
                }
                catch
                {
                    Console.WriteLine(query);
                    retVal = OracleDatabase.counter++;
                }
            }
            return retVal;
        }

        public static void finish()
        {
            if (!OracleDatabase._isTransaction)
                OracleDatabase._connection = null;
        }

        public static void commit()
        {
            try
            {
                //OracleDatabase._transaction.Commit();
            }
            catch
            {
                //OracleDatabase._transaction.Rollback();
            }
            finally
            {
                //OracleDatabase._connection.Close();
                OracleDatabase._isTransaction = false;
                OracleDatabase.finish();
            }
        }

        public static void rollback()
        {
            //OracleDatabase._transaction.Rollback();
            //OracleDatabase._connection.Close();
            OracleDatabase._isTransaction = false;
            OracleDatabase.finish();
        }
    }
}